package com.zzgele.qmzb.api.dao;

import com.zzgele.qmzb.api.core.Mapper;
import com.zzgele.qmzb.api.model.Room;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public interface RoomMapper extends Mapper<Room> {

    
    List<HashMap> getListByDistance(Map<String, Object> map);
    
    @Select("select ticket_total from user u join room r on u.id=r.uid where r.roomid =#{roomId}")
    BigDecimal getTotalTicket(Long roomId);

    @Select(" SELECT SUM(gl.diamond) AS contribution\n" +
            "        FROM gift_log gl\n" +
            "         WHERE gl.uid = #{login_uid}\n" +
            "        and gl.tuid = #{anchor_uid}")
    BigDecimal getTotalDiamond(@Param("login_uid") Long login_uid, @Param("anchor_uid") Long anchor_uid);

    @Select("select count(*) from room  where status=1")
    int getLivingCount();


    @Select("select r.`status` AS live_status,u.nick_name,u.icon user_picture,u.icon,u.number,r.roomid,r.room_user_count,r.hls_pull_array,r.hls_pull_url,r.rtmp_pull_url,r.cid from user u join room r on u.id=r.uid where u.id =#{uid}")
    HashMap getMyInfo(Long uid);

    @Select("select sum(amount*diamond)   from gift_log  where tuid=#{uid} and create_time>#{startTime}")
    BigDecimal getTheLivingTicket(@Param("uid") Long uid, @Param("startTime") Integer startTime);
    //关闭直播间
    @Update("update room set status=#{status},room_user_count=0 where pullid=#{cid}  ")
    Integer closeLivingRoom(@Param("cid") String cid, @Param("status") String status);

    List<HashMap> getOfficialList(Map<String, Object> map);

}